package cn.edu.cqu.fredyvia.forum.service.impl;

import cn.edu.cqu.fredyvia.forum.dto.CommentDTO;
import cn.edu.cqu.fredyvia.forum.entity.Comment;
import cn.edu.cqu.fredyvia.forum.entity.CommentThumb;
import cn.edu.cqu.fredyvia.forum.mapper.CommentMapper;
import cn.edu.cqu.fredyvia.forum.mapper.CommentThumbMapper;
import cn.edu.cqu.fredyvia.forum.service.ICommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fredyvia
 * @since 2021-07-10
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {
    @Autowired
    CommentMapper commentMapper;

    @Autowired
    CommentThumbMapper commentThumbMapper;

    @Override
    public List<CommentDTO> listByTalkId(int talkId) {
        List<CommentDTO> commentDTOList = commentMapper.listByTalkId(talkId);
        for (CommentDTO commentDTO:commentDTOList){
            commentDTO.setThumb_sum(commentThumbMapper.selectCount(new QueryWrapper<CommentThumb>().eq("comment_id",commentDTO.getId())));
        }
        return commentDTOList;
    }

    @Override
    public CommentDTO one(int commentId) {
        return commentMapper.one(commentId);
    }
}
